<?php

require_once __dir__.'/../common.php';

define ('DOT_SIZE', 1);

$size = $_REQUEST['size'] ? $_REQUEST['size'] : MINI_MAP_SIZE;
$image = imagecreatefromgif(PLAYGROUND_MAP_IMAGE_FILE);
$image_p = imagecreatetruecolor($size, $size);

imagecopyresized($image_p, $image, 0, 0, 0, 0,
	$size, $size, imagesx($image), imagesy($image));

$scale = $size/imagesx($image);
$result = sys::sql("select * from items where item_x != '';");

$user_id = user::getId();

if (!empty($result))
{
	$red = imagecolorallocate($image_p, 255, 0, 0); 
	$green = imagecolorallocate($image_p, 0, 255, 0); 
	$orange = imagecolorallocate($image_p, 255, 127, 66); 
	foreach ($result as $v)
	{
		$x = $v['item_x']*$scale;
		$y = $v['item_y']*$scale;
		if ($user_id == $v['user_id'])
		{
			imagefilledrectangle($image_p, $x-DOT_SIZE, $y-DOT_SIZE, $x+DOT_SIZE, $y+DOT_SIZE, $red);
		}
		else
		{
			imagefilledrectangle($image_p, $x-DOT_SIZE, $y-DOT_SIZE, $x+DOT_SIZE, $y+DOT_SIZE, $green);
		}
	}
}




header('Content-type: image/jpeg');
imagejpeg($image_p, null, 100);
